package com.epoque.admin.server.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import com.epoque.admin.server.mapper.MenuMapper;
import com.epoque.admin.server.mapper.UserMapper;
import com.epoque.admin.server.model.User;
import com.epoque.common.biz.BaseBiz;
import com.epoque.common.constant.UserConstant;

/**
 * 
 * @ClassName: UserService
 * @Description: 用户操作类
 * @author qiuxianfeng
 * @date 2018年8月29日
 *
 */
@Service
public class UserService extends BaseBiz<UserMapper,User> {

    @Autowired
    private MenuMapper menuMapper;
    
    @Override
    public void insertSelective(User entity) {
        String password = new BCryptPasswordEncoder(UserConstant.PW_ENCORDER_SALT).encode(entity.getPassword());
        entity.setPassword(password);
        super.insertSelective(entity);
    }

    @Override
    public void updateSelectiveById(User entity) {
        String password = new BCryptPasswordEncoder(UserConstant.PW_ENCORDER_SALT).encode(entity.getPassword());
        entity.setPassword(password);
        super.updateById(entity);
    }

    /**
     * 
     * @Title: getUserByUsername
     * @author qiuxianfeng
     * @Description: 根据用户名获取用户信息
     * @param @param username
     * @param @return    参数
     * @return User    返回类型
     * @throws
     */
    public User getUserByUsername(String username){
        User user = new User();
        user.setUsername(username);
        return mapper.selectOne(user);
    }
   
}
